Add X3M SDK and Loomit adapters to your app
Cocoapods
We recommend using Cocoapods to integrate the SDK. Open your Podfile and add this line at the beginning:
source 'https://github.com/x3mads/podspecs.git'
You will also need to add the following line inside your app's target:
- Core dependency for Swift
- Core dependency for Objective-C
pod 'XMediator'
pod 'XMediatorObjC'
Finally, run from the command line:
pod install --repo-update
Choose Mediators and Networks
Use the following tool to generate compatible dependencies for the Networks and Mediation SDKs of your choice.
If you're looking to integrate an ad network that isn't currently listed, please contact our team or your account representative to discuss support and integration options.
Initialize the SDK
If you previously used a different mediation platform, remove any related initialization and configuration code, and ensure there is no interaction with any of its code while Loomit is active.
Before requesting any ad, make sure to call XMediatorAds.startWith()
(or platform equivalent). This method configures your application Key, and fetches the required configuration parameters for the ad placements in your app, among other things.
Additionally, you may want to wait for the initialization callback to complete. This will ensure that your placement requests have the necessary prebid configurations.
Example Swift/Objective-C
In addition to the example below, you can see a real implementation in our iOS Demo App.
- Swift
- Objective-C
import XMediator
var customProperties = CustomProperties()
customProperties.addString(key: "key1", value: "initialValue")
customProperties.addInt(key: "key2", value: 100)
customProperties.addBoolean(key: "key3", value: true)
let userProperties = UserProperties (
userId: "<an-optional-unique-user-id>",
customProperties: customProperties
)
let initSettings = InitSettings(userProperties: userProperties)
XMediatorAds.startWith(appKey: "<your-app-key>",
initSettings: initSettings) { result in
print("Initialization complete! You can start loading your placements!")
}
@import XMediatorObjC;
X3MUserProperties *userProperties = [X3MUserProperties new];
userProperties.userId = @"<an-optional-unique-user-id>";
X3MCustomProperties *properties = [X3MCustomProperties new];
[properties addStringWithKey:@"key1" value:@"initialValue"];
[properties addIntWithKey:@"key2" value:100];
[properties addBoolWithKey:@"key3" value:YES];
userProperties.customProperties = properties;
X3MInitSettings *initSettings = [X3MInitSettings new];
initSettings.userProperties = userProperties;
[X3MXMediatorAds startWithAppKey:@"<your-app-key>"
initSettings:initSettings
callback:^(NSError * _Nullable error) {
NSLog(@"Initialization complete! You can start loading your placements!");
}];
To ensure the SDK is correctly configured before ad mediation begins, any method that performs an ad request will raise an exception if they are called before XMediatorAds.startWith()
(or platform equivalent) is invoked.
It is mandatory to wait for the init callback to complete before making any ad request.
Update User Properties
After the SDK has been initialized, you can update the user properties (and custom properties) at any time. You may modify, add, or remove properties as needed.
To ensure you do not overwrite the entire configuration, always follow these steps:
- Retrieve the current user properties.
- Edit only the properties you want to change using the editor.
- Pass the updated properties to
setUserProperties
to apply your changes.
Below you can see how to do this:
- Swift
- Objective-C
var userProperties = XMediatorAds.getUserProperties()
// Modify key1
userProperties.customProperties.addString(key: "key1", value: "updatedValue")
// Remove key2
userProperties.customProperties.remove(key: "key2")
// key3 remains unchanged
// Add key4
userProperties.customProperties.addArray(key: "key4", value: ["new1", "new2"])
XMediatorAds.setUserProperties(userProperties)
X3MUserProperties *updatedUserProperties = [X3MXMediatorAds getUserProperties];
[updatedUserProperties.customProperties
// Modify key1
addStringWithKey:@"key1" value:@"updatedValue"];
// Remove key2
[updatedUserProperties.customProperties removeWithKey:@"key2"];
// key3 remains unchanged
// Add new key4
[updatedUserProperties.customProperties addArrayWithKey:@"key4" value:@[@"new1", @"new2"]];
[X3MXMediatorAds setUserProperties:updatedUserProperties];
SKAdNetwork
Add the SKAdNetwork IDs for the networks you selected above to your app’s Info.plist
by following the instructions .